package com.ruoyi.web.controller.systembasic;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesWareLocator;
import com.ruoyi.mes.systembasic.service.ISmesWareLocatorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库位管理Controller
 * 
 * @author yanqin
 * @date 2020-11-23
 */
@RestController
@RequestMapping("/systembasic/warelocator")
public class SmesWareLocatorController extends BaseController
{
    @Autowired
    private ISmesWareLocatorService smesWareLocatorService;

    /**
     * 查询库位管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:warelocator:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesWareLocator smesWareLocator)
    {
        startPage();
        List<SmesWareLocator> list = smesWareLocatorService.selectSmesWareLocatorList(smesWareLocator);
        return getDataTable(list);
    }

    /**
     * 导出库位管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:warelocator:export')")
    @Log(title = "库位管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesWareLocator smesWareLocator)
    {
        List<SmesWareLocator> list = smesWareLocatorService.selectSmesWareLocatorList(smesWareLocator);
        ExcelUtil<SmesWareLocator> util = new ExcelUtil<SmesWareLocator>(SmesWareLocator.class);
        return util.exportExcel(list, "warelocator");
    }

    /**
     * 获取库位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:warelocator:query')")
    @GetMapping(value = "/{wareLocatorNo}")
    public AjaxResult getInfo(@PathVariable("wareLocatorNo") String wareLocatorNo)
    {
        return AjaxResult.success(smesWareLocatorService.selectSmesWareLocatorById(wareLocatorNo));
    }

    /**
     * 新增库位管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:warelocator:add')")
    @Log(title = "库位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesWareLocator smesWareLocator)
    {
        smesWareLocator.setCreateUserName(SecurityUtils.getUsername());
        return toAjax(smesWareLocatorService.insertSmesWareLocator(smesWareLocator));
    }

    /**
     * 修改库位管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:warelocator:edit')")
    @Log(title = "库位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesWareLocator smesWareLocator)
    {
        smesWareLocator.setUpdateUserName(SecurityUtils.getUsername());
        return toAjax(smesWareLocatorService.updateSmesWareLocator(smesWareLocator));
    }

    /**
     * 删除库位管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:warelocator:remove')")
    @Log(title = "库位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wareLocatorNos}")
    public AjaxResult remove(@PathVariable String[] wareLocatorNos)
    {
        return toAjax(smesWareLocatorService.deleteSmesWareLocatorByIds(wareLocatorNos));
    }
}
